package com.oj.judge.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.oj.common.annotation.Log;
import com.oj.common.core.controller.BaseController;
import com.oj.common.core.domain.AjaxResult;
import com.oj.common.enums.BusinessType;
import com.oj.judge.domain.OjSubmission;
import com.oj.judge.service.IOjSubmissionService;
import com.oj.common.utils.poi.ExcelUtil;
import com.oj.common.core.page.TableDataInfo;

/**
 * 测评状态Controller
 * 
 * @author xxx
 * @date 2025-03-16
 */
@RestController
@RequestMapping("/judge/judge")
public class OjSubmissionController extends BaseController
{
    @Autowired
    private IOjSubmissionService ojSubmissionService;

    /**
     * 查询测评状态列表
     */
    @PreAuthorize("@ss.hasPermi('judge:judge:list')")
    @GetMapping("/list")
    public TableDataInfo list(OjSubmission ojSubmission)
    {
        startPage();
        List<OjSubmission> list = ojSubmissionService.selectOjSubmissionList(ojSubmission);
        return getDataTable(list);
    }

    /**
     * 导出测评状态列表
     */
    @PreAuthorize("@ss.hasPermi('judge:judge:export')")
    @Log(title = "测评状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OjSubmission ojSubmission)
    {
        List<OjSubmission> list = ojSubmissionService.selectOjSubmissionList(ojSubmission);
        ExcelUtil<OjSubmission> util = new ExcelUtil<OjSubmission>(OjSubmission.class);
        util.exportExcel(response, list, "测评状态数据");
    }

    /**
     * 获取测评状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('judge:judge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ojSubmissionService.selectOjSubmissionById(id));
    }

    /**
     * 新增测评状态
     */
    @PreAuthorize("@ss.hasPermi('judge:judge:add')")
    @Log(title = "测评状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OjSubmission ojSubmission)
    {
        return toAjax(ojSubmissionService.insertOjSubmission(ojSubmission));
    }

    /**
     * 修改测评状态
     */
    @PreAuthorize("@ss.hasPermi('judge:judge:edit')")
    @Log(title = "测评状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OjSubmission ojSubmission)
    {
        return toAjax(ojSubmissionService.updateOjSubmission(ojSubmission));
    }

    /**
     * 删除测评状态
     */
    @PreAuthorize("@ss.hasPermi('judge:judge:remove')")
    @Log(title = "测评状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ojSubmissionService.deleteOjSubmissionByIds(ids));
    }
}
